import axios from 'axios';

// 创建axios实例
const api = axios.create({
  baseURL: 'http://127.0.0.1:5000/api',
  timeout: 30000 // 增加超时时间到30秒
});

// 部门相关API
export const getDepartments = () => api.get('/departments');
// 打印从后端获取的部门数据
// console.log('从后端获取的部门数据:', await getDepartments());

export const getDepartment = (id) => api.get(`/departments/${id}`);

// 文件相关API
export const getFiles = (params = {}) => api.get('/files', { params });

export const uploadFile = (formData) => api.post('/files', formData, {
  headers: {
    'Content-Type': 'multipart/form-data'
  }
});

export const deleteFile = (id) => api.delete(`/files/${id}`);

export const downloadFile = (id) => api.get(`/files/download/${id}`, {
  responseType: 'blob',
  timeout: 30000 // 增加超时时间到30秒
});

export default api;